
<!--员工登录组件-->

<template>
  <div class="LoginDiv">
    <el-form :model="loginForm" :rules="loginRule" ref="loginForm" label-position="left">
      <el-form-item label="username">
        <el-input v-model="loginForm.username"></el-input>
      </el-form-item>
      <el-form-item label="password">
        <el-input v-model="loginForm.password" show-password></el-input>
      </el-form-item>
      <el-form-item style="text-align: right">
        <el-button @click="verifyLogin">sign in</el-button>
        <el-button @click="regist">regist</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import global from "assets/global"
import cookies from 'js-cookie'
  export default {
    name: "NormalLogin",
    data(){
      return{
        //用户名密码
        loginForm:{
          username:'',
          password:'',
        },
        //用户名密码输入规则
        loginRule: {
          username: [
            { required: true, message: '请输入用户名', trigger: 'blur' }
          ],
          pwd: [
            { required: true, message: '请输入密码', trigger: 'blur' }
          ]
        },
      }
    },

    methods:{
      //提交登录表单
      async verifyLogin(){
        let mydata = this.loginForm;
        this.$axios.post('/login',mydata).then((res)=>{
          console.log(res)
          if(res.data.code){
            alert("密码错误")
            return
          }
          this.$message.success("登录成功")
          cookies.set('userInfo',res.data.msg)
          cookies.set('user_id',res.data.msg.user_id)
          cookies.set('user_role',1)
          // cookies.set('user_role',res.data.msg.user_role)
          this.$router.push('/ViewMovie')

        })
      },
      async regist(){
        this.$router.push('/regist')//注册
      }

    }
  }
</script>

<style scoped>

</style>

